﻿//------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , Criway , Ltd. 
//------------------------------------------------------------

using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using System.IO;
using System.Data;
using CrazyTalk.Common;
using System.Xml;
using CrazyTalk.Config;
using CrazyTalk.Models;

namespace CrazyTalk.Web.UI
{
    /// <remarks>
    /// BasePage
    /// 
    /// 修改纪录
    /// 
    ///	版本：2.4 2008.03.17    Criway    登录程序改进为面向服务的登录。
    ///	版本：2.3 2008.03.07    Criway    登录时页面重新导向功能改进。
    ///	版本：2.2 2007.12.09    Criway    获得页面权限的 GetPermission 函数改进。
    ///	版本：2.1 2007.12.08    Criway    单点登录功能完善。
    ///	版本：2.0 2006.02.02    Criway    页面注释都修改好。
    ///	
    /// 版本：2.4
    /// <author>
    ///		<name>Criway</name>
    ///		<date>2008.03.17</date>
    /// </author> 
    /// </remarks>
    public class BasePage : Page, IHandler
    {
        /// <summary>
        /// 使用的换行符号，比如\n 或 <br/>
        /// </summary>
        public const string LineBreakSymbol = "\n";

        protected String UploadFiles = "UploadFiles";                        // 上传文件的路径定义
        protected String EnableState = "<font color=\"#CC0000\">√<font>";   // 有效显示字符串定义
        protected String DisableState = "<font color=\"#CC0000\">-<font>";   // 无效显示字符串定义
        protected bool ShowInformation = true;                               // 是否显示提示信息


        private BaseUserInfo userInfo = null;                       // 当前操作员信息对象
        protected BaseUserInfo UserInfo
        {
            get
            {
                if (HttpContext.Current.Session["UserInfo"] != null)
                {
                    this.userInfo = (BaseUserInfo)HttpContext.Current.Session["UserInfo"];
                }
                if (this.userInfo == null)
                {
                    // 从 Session 读取 当前操作员信息
                    if (HttpContext.Current.Session["UserInfo"] == null)
                    {
                        this.userInfo = new BaseUserInfo();
                        // 获得IP 地址
                        this.userInfo.ID = Context.Request.ServerVariables["REMOTE_ADDR"];
                        this.userInfo.Realname = Context.Request.ServerVariables["REMOTE_ADDR"];
                        this.userInfo.Username = Context.Request.ServerVariables["REMOTE_ADDR"];
                        this.userInfo.IPAddress = Context.Request.ServerVariables["REMOTE_ADDR"];
                    }
                }
                return this.userInfo;
            }
            set
            {
                this.userInfo = value;
            }
        }

        protected String LangSaveConfirm = " You confirm must preserve? ";	// 您确认要保存吗
        protected String LangDeleteConfirm = " You confirm must delete? ";	    // 您确认要删除吗
        protected String LangConfirm = " Please careful checkup data! The confirmation input is correct? "; // 请仔细核对数据，确认输入的正确吗？

        protected String CompanyFullName = String.Empty;   // 公司名称   
        protected String SoftFullName = String.Empty;   // 软件名称  
        protected String Version = String.Empty;   // 版本号
        protected String IEDownloadUrl = String.Empty;   // IE下载地址
        protected String Designed = String.Empty;   // 设计者
        protected String Update = String.Empty;   // 更新

        protected String NotFindPage = @"Index.aspx";    // 内容未找到页面
        //protected String UserNotLogin = @"Login.aspx";  // 用户未登录页面
        protected String UserNotLogin = ApplicationPath + "/Login.aspx";
        protected String AccessDenyPage = @"Index.aspx";    // 访问没有权限被拒绝页面
        protected String UserIsNotAdminPage = @"Index.aspx";    // 当前操作员不是系统管理员页面

        private static string _ApplicationPath;
        /// <summary>
        /// 虚拟应用程序根路径
        /// </summary>
        public static string ApplicationPath
        {
            get
            {
                _ApplicationPath = HttpContext.Current.Request.ApplicationPath;
                if (_ApplicationPath.Length == 1)
                {
                    _ApplicationPath = "";
                }

                return HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.AbsolutePath, "") + _ApplicationPath;
            }
        }

        protected bool SimpleManagerMode = true;            // 选择是简易管理模式，是否部门管理权限管理角色管理等页面很复杂？
        public String SUID = String.Empty;    // 单点登录唯一识别标识

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region protected override void OnInit(EventArgs e) 所有页面加载时默认运行的方法
        /// <summary>
        /// 所有页面加载时默认运行的方法
        /// </summary>
        /// <param name="e">系统默认参数</param>
        protected override void OnInit(EventArgs e)
        {
            //UserNotLogin = Server.MapPath("~/Login.aspx");
            //this.GetParamter();
            //if (!this.UserIsLogin())
            //{

            //if (this.SUID.Length > 0)
            //{
            //    this.Login(this.SUID);
            //}
            // 判断用户是否已登录
            // this.UserIsLogin();

            //检查用户是否已登录
            this.CheckIsLogin();

            //}
            // 统一的错误处理页面部分
            // this.Error += new EventHandler(BasePage_Error);
        }
        #endregion

        #region public void GetParamter() 所有页面基础类的，活得单点登录唯一识别标识的方法
        /// <summary>
        ///所有页面基础类的，活得单点登录唯一识别标识的方法
        /// </summary>
        public void GetParamter()
        {
            if (Page.Request["SUID"] != null)
            {
                this.SUID = Page.Request["SUID"].ToString();
            }
        }
        #endregion

        #region private String GetSession(String paramSession) 安全获取Session的值
        /// <summary>
        /// 安全获取Session的值
        /// </summary>
        /// <param name="paramSession">变量名</param>
        /// <returns>字符串</returns>
        private String GetSession(String paramSession)
        {
            String returnValue = String.Empty;
            if (HttpContext.Current.Session[paramSession] != null)
            {
                returnValue = HttpContext.Current.Session[paramSession].ToString();
            }
            return returnValue;
        }
        #endregion

        #region protected String CheckCodeImage 登录验证码读取
        /// <summary>
        /// 登录验证码读取
        /// </summary>
        protected String CheckCodeImage
        {
            get
            {
                return this.GetSession("LoginCheckCode");
            }
            set
            {
                HttpContext.Current.Session["LoginCheckCode"] = value;
            }
        }
        #endregion

        #region protected void GetConfiguration() 读取一些基本配置信息
        /// <summary>
        /// 读取一些基本配置信息
        /// </summary>
        protected void GetConfiguration()
        {
            // 获取一些显示信息
            this.CompanyFullName = ConfigurationManager.AppSettings["CustomerCompanyName"];
            this.SoftFullName = ConfigurationManager.AppSettings["SoftFullName"];
            this.Version = ConfigurationManager.AppSettings["Version"];
            this.IEDownloadUrl = ConfigurationManager.AppSettings["IEDownloadUrl"];
            this.Designed = ConfigurationManager.AppSettings["Designed"];
            this.Update = ConfigurationManager.AppSettings["Update"];
        }
        #endregion

        #region protected void GetConfig() 读取一些基本配置信息
        /// <summary>
        /// 读取一些基本配置信息
        /// </summary>
        protected void GetConfig()
        {
            // 获取一些运行模式参数
            // this.UserInfo.RunMode = BaseConfiguration.Instance.RunMode;
            // this.UserInfo.WebService = BaseConfiguration.Instance.WebService;
            //this.UserInfo.WebServiceUsername = BaseConfiguration.Instance.WebServiceUsername;
            //this.UserInfo.WebServicePassword = BaseConfiguration.Instance.WebServicePassword;
        }
        #endregion

        #region public void LogException(Exception exception) 记录异常信息
        /// <summary>
        /// 记录异常信息
        /// </summary>
        /// <param name="exception">异常信息实体</param>
        public void LogException(Exception exception)
        {
            //BaseExceptionDao.LogException(this.DbHelper, this.UserInfo, exception);
        }
        #endregion

        #region public void SetDropDownListValue(DropDownList dropDownList, String selectedValue)
        /// <summary>
        /// 设置下拉框的被选中值
        /// </summary>
        /// <param name="dropDownList">下拉框</param>
        /// <param name="selectedValue">被选中的值</param>
        public void SetDropDownListValue(DropDownList dropDownList, String selectedValue)
        {
            if (dropDownList.SelectedItem != null)
            {
                dropDownList.SelectedItem.Selected = false;
            }
            // 按值找
            ListItem listItem = dropDownList.Items.FindByValue(selectedValue);
            if (listItem == null)
            {
                // 按显示的文本找
                for (int i = 0; i < dropDownList.Items.Count; i++)
                {
                    if (dropDownList.Items[i].Text.Equals(selectedValue))
                    {
                        dropDownList.Items[i].Selected = true;
                        break;
                    }
                }
                // 还是没找到
                if (dropDownList.SelectedItem == null)
                {
                    listItem = new ListItem(selectedValue, selectedValue);
                    dropDownList.Items.Insert(0, listItem);
                }
            }
            else
            {
                // 设置为被选中状态
                listItem.Selected = true;
            }
        }
        #endregion


        //
        // 当前操作员权限相关检查函数
        //

        #region public bool UserIsLogin() 判断用户是否已登录
        /// <summary>
        /// 判断用户是否已登录
        /// </summary>
        /// <returns>是否</returns>
        public bool UserIsLogin()
        {
            if (HttpContext.Current.Session["UserInfo"] == null)
            {
                this.CheckCookie();
            }
            return HttpContext.Current.Session["UserInfo"] != null;
        }
        #endregion

        #region public bool UserIsAdministrator() 判断当前用户是否为系统管理员
        /// <summary>
        /// 判断当前用户是否为系统管理员
        /// </summary>
        /// <returns>是否</returns>
        public bool UserIsAdministrator()
        {
            bool returnValue = false;
            if (this.UserIsLogin())
            {
                BaseUserInfo userInfo = (BaseUserInfo)Session["UserInfo"];
                returnValue = userInfo.IsAdministrator;
            }
            return returnValue;
        }
        #endregion

        #region public bool CheckIsLogin() 检查是否已登录
        /// <summary>
        /// 检查是否已登录
        /// </summary>
        public void CheckIsLogin()
        {
            if (!this.UserIsLogin())
            {
                //Page.Response.Write("<script type='text/javascript'>parent.document.location='Login.aspx'</script>");
                //Page.Response.Redirect(this.UserNotLogin);
                string LoginUrl = Page.Request.Url.ToString().Replace(Page.Request.RawUrl, "");
                //LoginUrl = LoginUrl + "/Login.html";
                //Page.Response.Write("<script type='text/javascript'>parent.document.location='" + LoginUrl + "'</script>");
                Page.Response.Write("logout");
                Page.Response.End();
            }
        }
        #endregion

        #region public void CheckIsAdministrator() 检查判断当前用户是否为系统管理员
        /// <summary> 
        /// 检查判断当前用户是否为系统管理员
        /// </summary>
        public void CheckIsAdministrator()
        {
            // 检查是否已登录
            this.CheckIsLogin();
            // 是否系统管理员
            if (!this.UserIsAdministrator())
            {
                Page.Response.Redirect(this.UserIsNotAdminPage);
            }
        }
        #endregion

        #region public bool IsAuthorized(String permissionCode) 是否有相应的权限
        /// <summary>
        /// 是否有相应的权限
        /// </summary>
        /// <param name="permissionCode">权限编号</param>
        /// <returns>是否有权限</returns>
        public bool IsAuthorized(String permissionCode)
        {
            return false;
            //return BaseResourcePermissionDao.Instance.CheckPermission(this.DbHelper, this.UserInfo, permissionCode);
        }
        #endregion

        #region public DataTable DTPermission 当前操作员的权限数据，一个页面里只读取一次就可以了，不用反复读取权限，可以在 Session 里缓存起来
        /// <summary>
        /// 当前操作员的权限数据，一个页面里只读取一次就可以了，不用反复读取权限，可以在 Session 里缓存起来
        /// </summary>
        public DataTable DTPermission
        {
            get
            {
                return this.GetFromSession("DTPermission") as DataTable;
            }
            set
            {
                this.AddSession("DTPermission", value);
            }
        }
        #endregion


        //
        // 表格选择记录功能部分 GridView
        //

        #region public string[] GetSelecteIDs(GridView gridView) 获得已选的表格行代码数组
        /// <summary>
        /// 获得已选的表格行代码数组
        /// </summary>
        /// <param name="gridView">表格</param>
        /// <returns>代码数组</returns>
        public string[] GetSelecteIDs(GridView gridView)
        {
            return this.GetSelecteIDs(gridView, true);
        }
        #endregion

        #region public string[] GetUnSelecteIDs(GridView gridView) 获得未选的表格行代码数组
        /// <summary>
        /// 获得未选的表格行代码数组
        /// </summary>
        /// <param name="gridView">表格</param>
        /// <returns>代码数组</returns>
        public string[] GetUnSelecteIDs(GridView gridView)
        {
            return this.GetSelecteIDs(gridView, false);
        }
        #endregion

        #region public string[] GetSelecteIDs(GridView gridView, bool paramChecked)
        /// <summary>
        /// 获得表格行代码数组
        /// </summary>
        /// <param name="gridView">表格</param>
        /// <param name="paramChecked">选中状态</param>
        /// <returns>代码数组</returns>
        public string[] GetSelecteIDs(GridView gridView, bool paramChecked)
        {
            return GetSelecteIDs(gridView, paramChecked, "chkSelected");
        }
        #endregion

        #region public string[] GetSelecteIDs(GridView gridView, bool paramChecked, String paramControl)
        /// <summary>
        /// 获得已选的表格行代码数组
        /// </summary>
        /// <param name="gridView">表格</param>
        /// <param name="paramChecked">选中状态</param>
        /// <param name="paramControl">控件名称</param>
        /// <returns>代码数组</returns>
        public string[] GetSelecteIDs(GridView gridView, bool paramChecked, String paramControl)
        {
            string[] paramIDs = new string[0];
            String IDs = String.Empty;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                // 得到选中的ID
                if (gridView.Rows[i].RowType == DataControlRowType.DataRow)
                {
                    TableCell tableCell = gridView.Rows[i].Cells[0];
                    CheckBox checkBox = (CheckBox)tableCell.FindControl(paramControl);
                    if (checkBox != null)
                    {
                        if (checkBox.Checked == paramChecked)
                        {
                            // 把选中的ID保存到字符串
                            String ID = gridView.DataKeys[gridView.Rows[i].RowIndex].Value.ToString();
                            if (ID.Length > 0)
                            {
                                IDs += ID + ",";
                            }
                        }
                    }
                }
            }
            // 切分ID
            if (IDs.Length > 1)
            {
                IDs = IDs.Substring(0, IDs.Length - 1);
                paramIDs = IDs.Split(',');
            }
            return paramIDs;
        }
        #endregion

        //
        // 表格选择记录功能部分 DataGrid
        //

        #region public String[] GetSelecteIDs(DataGrid dataGrid) 获得已选的表格行代码数组
        /// <summary>
        /// 获得已选的表格行代码数组
        /// </summary>
        /// <param name="dataGrid">表格</param>
        /// <returns>代码数组</returns>
        public String[] GetSelecteIDs(DataGrid dataGrid)
        {
            return this.GetSelecteIDs(dataGrid, true);
        }
        #endregion

        #region public String[] GetUnSelecteIDs(DataGrid dataGrid) 获得未选的表格行代码数组
        /// <summary>
        /// 获得未选的表格行代码数组
        /// </summary>
        /// <param name="dataGrid">表格</param>
        /// <returns>代码数组</returns>
        public String[] GetUnSelecteIDs(DataGrid dataGrid)
        {
            return this.GetSelecteIDs(dataGrid, false);
        }
        #endregion

        #region public String[] GetSelecteIDs(DataGrid dataGrid, bool paramChecked)
        /// <summary>
        /// 获得表格行代码数组
        /// </summary>
        /// <param name="dataGrid">表格</param>
        /// <param name="paramChecked">选中状态</param>
        /// <returns>代码数组</returns>
        public String[] GetSelecteIDs(DataGrid dataGrid, bool paramChecked)
        {
            return GetSelecteIDs(dataGrid, paramChecked, "chkSelected");
        }
        #endregion

        #region public String[] GetSelecteIDs(DataGrid dataGrid, bool paramChecked, String paramControl)
        /// <summary>
        /// 获得已选的表格行代码数组
        /// </summary>
        /// <param name="gridView">表格</param>
        /// <param name="paramChecked">选中状态</param>
        /// <param name="paramControl">控件名称</param>
        /// <returns>代码数组</returns>
        public String[] GetSelecteIDs(DataGrid dataGrid, bool paramChecked, String paramControl)
        {
            string[] paramIDs = new string[0];
            String IDs = String.Empty;
            for (int i = 0; i < dataGrid.Items.Count; i++)
            {
                // 得到选中的ID
                TableCell myTableCell = dataGrid.Items[i].Cells[0];
                CheckBox myCheckBox = (CheckBox)myTableCell.FindControl(paramControl);
                if (myCheckBox != null)
                {
                    if (myCheckBox.Checked == paramChecked)
                    {
                        // 把选中的ID保存到字符串
                        String ID = dataGrid.DataKeys[dataGrid.Items[i].ItemIndex].ToString();
                        if (ID.Length > 0)
                        {
                            IDs += ID + ",";
                        }
                    }
                }
            }
            // 切分ID
            if (IDs.Length > 1)
            {
                IDs = IDs.Substring(0, IDs.Length - 1);
                paramIDs = IDs.Split(',');
            }
            return paramIDs;
        }
        #endregion


        //
        // 登录功能相关部分
        //

        #region public void SaveCookie(String userName, String paramPassword)
        /// <summary>
        ///  保存Cookie
        /// </summary>
        /// <param name="paramUserName">用户名</param>
        /// <param name="paramPassword">密码</param>
        public void SaveCookie(String userName, String paramPassword)
        {
            HttpCookie httpCookie = new HttpCookie(BaseConfiguration.COMPANY_NAME);
            httpCookie.Values[BaseConfiguration.CURRENT_USERNAME] = userName;
            if (BaseSystemInfo.SavePassword)
            {
                httpCookie.Values[BaseConfiguration.CURRENT_PASSWORD] = paramPassword;
            }
            // 设置过期时间为30天
            DateTime myDateTime = DateTime.Now;
            httpCookie.Expires = myDateTime.AddDays(30);
            Response.Cookies.Add(httpCookie);
        }
        #endregion

        #region public void ClearCookie()
        /// <summary>
        /// 清空cookie
        /// </summary>
        public void ClearCookie()
        {
            // 清空cookie
            HttpCookie httpCookie = new HttpCookie(BaseConfiguration.COMPANY_NAME);
            // 设置过期时间，1秒钟后删除cookie就不对了,得时间很长才可以服务器时间与客户时间的差距得考虑好
            httpCookie.Expires = new DateTime(1978, 05, 19);
            Response.Cookies.Add(httpCookie);
        }
        #endregion

        #region public HttpCookie CheckCookie()
        /// <summary>
        /// 检查当前的Cookie设置
        /// </summary>
        public HttpCookie CheckCookie()
        {
            String paramUserName = String.Empty;
            String paramPassword = String.Empty;
            // 取得cookie的保存信息
            HttpCookie httpCookie = Request.Cookies[BaseConfiguration.COMPANY_NAME];
            if (httpCookie != null)
            {
                // 读取用户名
                if (httpCookie.Values[BaseConfiguration.CURRENT_USERNAME] != null)
                {
                    paramUserName = httpCookie.Values[BaseConfiguration.CURRENT_USERNAME].ToString();
                    if (BaseSystemInfo.SavePassword)
                    {
                        // 读取密码
                        if (httpCookie.Values[BaseConfiguration.CURRENT_PASSWORD] != null)
                        {
                            paramPassword = httpCookie.Values[BaseConfiguration.CURRENT_PASSWORD].ToString();
                        }
                        // 进行登录
                        this.Login(paramUserName, paramPassword);
                    }
                }
            }
            return httpCookie;
        }
        #endregion

        #region public BaseUserInfo Login(String paramSUID)
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="paramSUID">当点登录识别码</param>
        public BaseUserInfo Login(String paramSUID)
        {
            // 统一的登录服务
            String returnStatusCode = String.Empty;
            String returnStatusMessage = String.Empty;
            //BaseUserInfo userInfo = ServiceManager.Instance.LoginService.LoginBySUID(this.UserInfo, paramSUID, out returnStatusCode, out returnStatusMessage);
            this.Login(userInfo, false);
            return userInfo;
        }
        #endregion

        #region public BaseUserInfo Login(String paramUserName, String paramPassword)
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="paramUserName">用户名</param>
        /// <param name="paramPasswor">密码</param>
        public BaseUserInfo Login(String paramUserName, String paramPassword)
        {
            return this.Login(paramUserName, paramPassword, false, false);
        }
        #endregion

        #region public BaseUserInfo Login(String paramUserName, String paramPassword, bool paramPersistCookie, bool paramFormsAuthentication)
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="paramUserName">用户名</param>
        /// <param name="paramPassword">密码</param>
        /// <param name="paramPersistCookie">是否保存密码</param>
        /// <param name="paramFormsAuthentication">是否需要重定位</param>
        public BaseUserInfo Login(String paramUserName, String paramPassword, bool paramPersistCookie, bool paramFormsAuthentication)
        {
            // 统一的登录服务
            String returnStatusCode = String.Empty;
            String returnStatusMessage = String.Empty;
            return this.Login(paramUserName, paramPassword, paramPersistCookie, paramFormsAuthentication, out returnStatusCode, out returnStatusMessage);
        }
        #endregion

        #region public BaseUserInfo Login(String userName, String password, bool persistCookie, bool formsAuthentication, out String returnStatusCode, out String returnStatusMessage)
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="persistCookie">是否保存密码</param>
        /// <param name="formsAuthentication">表单验证，是否需要重定位</param>
        /// <param name="returnStatusCode"></param>
        /// <param name="returnStatusMessage"></param>
        /// <returns></returns>
        public BaseUserInfo Login(String userName, String password, bool persistCookie, bool formsAuthentication, out String returnStatusCode, out String returnStatusMessage)
        {
            returnStatusCode = string.Empty;
            returnStatusMessage = string.Empty;

            // 统一的登录服务
            // BaseUserInfo userInfo = UserService.Instance.Login(this.UserInfo, paramUserName, paramPassword, out returnStatusCode, out returnStatusMessage);
            //BaseUserInfo userInfo = ServiceManager.Instance.LoginService.UserLogin(this.UserInfo, userName, password, out returnStatusCode, out returnStatusMessage);
            // 在本地模式登录
            // this.DbHelper.Open();
            // BUBaseLogin myBULogin = this.Login(myDbHelper, paramUserName, paramPassword);
            // this.DbHelper.Close();
            // 检查身份

            BaseUserInfo userInfo = new BaseUserInfo();
            if (returnStatusCode.Equals(StatusCode.OK.ToString()))
            {
                if (persistCookie)
                {
                    this.SaveCookie(userName, password);
                }
                this.Login(userInfo, formsAuthentication);
            }
            return userInfo;
        }
        #endregion

        #region public BaseUserInfo Login(IDbHelper myDbHelper, String paramUserName, String paramPassword)
        ///// <summary>
        ///// 验证用户
        ///// </summary>
        ///// <param name="myDbHelper">数据库连接</param>
        ///// <param name="paramUserName">用户名</param>
        ///// <param name="paramPassword">密码</param>
        ///// <param name="paramPersistCookie">是否保存密码</param>
        ///// <param name="paramFormsAuthentication">是否需要重定位</param>
        //public BaseUserInfo Login(IDbHelper myDbHelper, String paramUserName, String paramPassword)
        //{
        //    String returnStatusCode = String.Empty;
        //    this.DbHelper = myDbHelper;
        //    BaseUserDao userDao = new BaseUserDao(this.DbHelper, this.UserInfo);
        //    BaseUserInfo userInfo = userDao.Login(paramUserName, paramPassword, Request.ServerVariables["REMOTE_ADDR"], out returnStatusCode);
        //    return userInfo;
        //}
        #endregion

        #region public void Login(BaseUserInfo userInfo, bool redirectFrom)
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="userInfo">登录</param>
        /// <param name="redirectFrom">是否需要重定位</param>
        public void Login(BaseUserInfo userInfo, bool redirectFrom)
        {
            // 检查身份
            if ((userInfo != null) && (!string.IsNullOrEmpty(userInfo.ID)))
            {
                this.SetSession(userInfo);
                if (redirectFrom)
                {
                    FormsAuthentication.RedirectFromLoginPage(BaseConfiguration.COMPANY_NAME, false);
                }
            }
            else
            {
                // 清空cookie
                this.ClearCookie();
                // 签出当前的注册
                FormsAuthentication.SignOut();
                // 清除Seesion对象
                // Session.Abandon();
                HttpContext.Current.Session["UserInfo"] = null;
            }
        }
        #endregion

        #region public void SetSession(BaseUserInfo userInfo)
        /// <summary>
        /// 设置Session
        /// </summary>
        /// <param name="userInfo">操作员</param>
        public void SetSession(BaseUserInfo userInfo)
        {
            // 检查身份
            if (userInfo.ID.Length > 0)
            {
                if (userInfo.Role.Length == 0)
                {
                    //userInfo.Role = DefaultRole.Staff.ToString();
                }
                HttpContext.Current.Session["UserInfo"] = userInfo;		  // 操作员
            }
        }
        #endregion

        //
        // 排序功能部分
        //

        public String SortExpression
        {
            get
            {
                if (ViewState["sortExpression"] == null)
                {
                    ViewState["sortExpression"] = "CreateDate";
                }
                return ViewState["sortExpression"].ToString();
            }
            set
            {
                ViewState["sortExpression"] = value;
            }
        }

        public String SortDire
        {
            get
            {
                if (ViewState["sortDire"] == null)
                {
                    ViewState["sortDire"] = "DESC";
                }
                return ViewState["sortDire"].ToString();
            }
            set
            {
                ViewState["sortDire"] = value;
            }
        }

        public void AddSession(String key, Object myObject)
        {
            HttpContext.Current.Session.Add(key, myObject);
        }

        public Object GetFromSession(String key)
        {
            return HttpContext.Current.Session[key];
        }


        //
        // 上传下载文件部分
        //

        #region public String UpLoadFile(String categoryID, String objectID, System.Web.HttpPostedFile httpPostedFile, ref String loadDirectory, bool deleteFile) 上传文件
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="paramCategoryID">分类代码</param>
        /// <param name="paramObjectID">实物代码</param>
        /// <param name="httpPostedFile">被上传的文件</param>
        /// <param name="paramLoadDirectory">上传目录</param>
        /// <param name="paramDeleteFile">是否删除原文件夹</param>
        /// <returns>上传的文件位置</returns>
        public String UpLoadFile(String categoryID, String objectID, System.Web.HttpPostedFile httpPostedFile, ref String loadDirectory, bool deleteFile)
        {
            // 服务器上的绝对路径
            String rootPath = Page.Server.MapPath("~/") + UploadFiles + "\\";
            // 图片重新指定，这里主要是为了起备份的作用，按日期把新的照片备份好就可以了。
            if (loadDirectory.Length == 0)
            {
                // 当前日期
                // String dateTime = DateTime.Now.ToString(BaseSystemInfo.DateFormat).ToString();
                // loadDirectory = categoryID + "\\" + dateTime + "\\" + objectID;
                loadDirectory = categoryID + "\\" + objectID;
            }
            // 需要创建的目录，图片放在这里，为了保存历史纪录，使用了当前日期做为目录
            String makeDirectory = rootPath + loadDirectory;
            if (deleteFile)
            {
                // 删除原文件
                if (Directory.Exists(makeDirectory))
                {
                    Directory.Delete(makeDirectory, true);
                }
            }
            Directory.CreateDirectory(makeDirectory);
            // 获得文件名
            String fileName = Server.HtmlEncode(Path.GetFileName(httpPostedFile.FileName));
            // 图片重新指定，虚拟的路径
            // 这里还需要更新学生的最新照片
            String fileUrl = loadDirectory + "\\" + fileName;
            // 文件复制到相应的路径下
            String copyToFile = makeDirectory + "\\" + fileName;
            httpPostedFile.SaveAs(copyToFile);
            return fileUrl;
        }
        #endregion

        #region public String UpLoadFile(String categoryID, String objectID, String loadDirectory, bool deleteFile) 上传文件
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="categoryID">分类代码</param>
        /// <param name="objectID">实物代码</param>
        /// <param name="loadDirectory">上传目录</param>
        /// <param name="deleteFile">是否删除原文件夹</param>
        /// <returns>上传的文件位置</returns>
        public String UpLoadFile(String categoryID, String objectID, String loadDirectory, bool deleteFile)
        {
            return this.UpLoadFile(categoryID, objectID, Page.Request.Files[0], ref loadDirectory, deleteFile);
        }
        #endregion

        #region public String UpLoadFiles(String categoryID, String objectID, String upLoadDirectory) 上传文件
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="paramCategoryID">分类代码</param>
        /// <param name="paramObjectID">实物代码</param>
        /// <param name="upLoadDirectory">上传的目录</param>
        /// <returns>上传目录</returns>
        public String UpLoadFiles(String categoryID, String objectID, String upLoadDirectory)
        {
            // 上传文件的复制文件部分
            String upLoadFilePath = String.Empty;
            for (int i = 0; i < Page.Request.Files.Count; i++)
            {
                if (Page.Request.Files[i].ContentLength > 0)
                {
                    // 获取文件名
                    String fileName = Server.HtmlEncode(Path.GetFileName(Page.Request.Files[i].FileName));
                    upLoadFilePath = this.UpLoadFile(categoryID, objectID, Page.Request.Files[i], ref upLoadDirectory, false);
                }
            }
            return upLoadFilePath;
        }
        #endregion

        //
        // 获取图标地址
        //

        #region public string GetFileIcon(String fileName) 获取图标地址
        /// <summary>
        /// 获取图标地址
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <returns>图标地址</returns>
        public string GetFileIcon(String fileName)
        {
            // 这里是默认的图标
            String imageUrl = "Themes/Default/Images/Download.gif";
            // 截取后缀名,GetExtension读出来的后缀带"."的
            String extension = System.IO.Path.GetExtension(fileName).ToLower().Substring(1);
            // 这里查找是否有指定的图标
            if (File.Exists(Page.Server.MapPath("~/") + "Themes/Default/Images/" + extension + ".png"))
            {
                // 获取图标地址
                imageUrl = "Themes/Default/Images/" + extension + ".png";
            }
            return imageUrl;
        }
        #endregion

        #region protected bool CheckLAN()
        /// <summary>
        /// 当前电脑是否在局域网络里
        /// </summary>
        /// <returns></returns>
        protected bool CheckLAN()
        {
            if ((this.UserInfo.IPAddress.Substring(0, 3) == "127") || (this.UserInfo.IPAddress.Substring(0, 3) == "192") || (this.UserInfo.IPAddress.Substring(0, 3) == "10."))
            {
                return true;
            }
            return false;
        }
        #endregion

        #region protected void CloseWindow()
        /// <summary>
        /// 关闭窗体
        /// </summary>
        protected void CloseWindow()
        {
            Page.Response.Write("<script language=\"JavaScript\">");
            Page.Response.Write("window.close();");
            Page.Response.Write("</script>");
        }
        #endregion


        #region public bool ModuleIsAuthorized(String moduleCode) 是否有相应的模块权限
        /// <summary>
        /// 是否有相应的模块权限
        /// </summary>
        /// <param name="moduleCode">模块编号</param>
        /// <returns>是否有权限</returns>
        public bool ModuleIsAuthorized(String moduleCode)
        {
            if (this.UserInfo.IsAdministrator)
            {
                return true;
            }
            return false;
        }
        #endregion

        #region protected void GetModuleList()
        /// <summary>
        /// 获模块列表
        /// </summary>
        /// <param name="myDbHelper">数据库连接</param>
        protected void GetModuleList()
        {
            //IDbHelper dbHelper = DbHelperFactory.GetHelper();
            //try
            //{
            //    dbHelper.Open();
            //    BaseModuleDao moduleDao = new BaseModuleDao(dbHelper, this.UserInfo);
            //    //BaseModuleDao moduleDao = new BaseModuleDao(this.DbHelper, this.UserInfo);
            //    if (this.UserInfo.IsAdministrator)
            //    {
            //        this.DTModule = moduleDao.GetDT();
            //    }
            //    else
            //    {
            //        //this.DTModule = moduleDao.GetListByUser(this.UserInfo.ID);

            //        this.DTModule = moduleDao.GetDTByUser(this.userInfo.ID);
            //    }
            //    // 按有效的模块进行过滤
            //    BaseBusinessLogic.SetFilter(this.DTModule, BaseModuleTable.FieldEnabled, "1");
            //    this.DTModule.DefaultView.Sort = BaseModuleTable.FieldSortCode;
            //}
            //finally
            //{
            //    dbHelper.Close();
            //}
        }
        #endregion

        protected DataTable DTModule
        {
            get
            {
                // 判断是否有数据，若没数据自动读取一次
                if (HttpContext.Current.Session["_DTModule"] == null)
                {
                    this.GetModuleList();
                }
                return this.GetFromSession("_DTModule") as DataTable;
            }
            set
            {
                this.AddSession("_DTModule", value);
            }
        }

        protected string Querys(string value)
        {
            if (Request.QueryString[value] != null)
            {
                return Request.QueryString[value].ToString().Trim();
            }
            else
            {
                return "";
            }
        }

        protected string Forms(string value)
        {
            if (Request.Form[value] != null)
            {
                return Request.Form[value].ToString().Trim();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 用在页面的Page_Load上进行tree的结点输出
        /// </summary>
        /// <param name="dt">上级结单ID的子节点的数据集（主要字段为ID和Name两列）</param>
        /// <param name="createXmlUrl">生成XML输出的URL</param>
        /// <param name="operateUrl">树的子节点链接的URL</param>
        protected void OutTreeXml(DataTable dt, string createXmlUrl, string operateUrl)
        {
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/xml";
            Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");

            XmlDocument xmldoc = new XmlDocument();
            XmlElement rootElement = xmldoc.CreateElement("TreeNode");
            xmldoc.AppendChild(rootElement);

            if (dt.Rows.Count > 0)
            {
                DataRow drParent = dt.Rows[0];

                //if (Request.QueryString["id"].ToString() == "0")
                if (drParent["ParentID"].ToString() == "0")
                {
                    XmlElement fistElement = xmldoc.CreateElement("TreeNode");
                    fistElement.SetAttribute("id", drParent["ID"].ToString());//当前ID
                    fistElement.SetAttribute("text", drParent["Name"].ToString());//显示的文本
                    fistElement.SetAttribute("href", operateUrl + "?id=" + drParent["ID"].ToString() + "&" + "name=" + Server.UrlEncode(drParent["Name"].ToString()));
                    fistElement.SetAttribute("target", "RList");
                    fistElement.SetAttribute("img_src", "../images/folder.gif");
                    fistElement.SetAttribute("title", drParent["Name"].ToString());
                    fistElement.SetAttribute("Xml", createXmlUrl + "?id=" + drParent["ID"].ToString());
                    rootElement.AppendChild(fistElement);

                    dt.Rows.Remove(drParent);

                    foreach (DataRow dr in dt.Rows)
                    {
                        XmlElement childElement = xmldoc.CreateElement("TreeNode");
                        childElement.SetAttribute("id", dr["ID"].ToString());//当前ID
                        childElement.SetAttribute("text", dr["Name"].ToString());//显示的文本
                        childElement.SetAttribute("href", operateUrl + "?id=" + dr["ID"].ToString() + "&" + "name=" + Server.UrlEncode(dr["Name"].ToString()));
                        childElement.SetAttribute("target", "RList");
                        childElement.SetAttribute("img_src", "../images/folder.gif");
                        childElement.SetAttribute("title", dr["Name"].ToString());
                        childElement.SetAttribute("Xml", createXmlUrl + "?id=" + dr["ID"].ToString());
                        fistElement.AppendChild(childElement);
                    }


                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        XmlElement childElement = xmldoc.CreateElement("TreeNode");
                        childElement.SetAttribute("id", dr["ID"].ToString());//当前ID
                        childElement.SetAttribute("text", dr["Name"].ToString());//显示的文本
                        childElement.SetAttribute("href", operateUrl + "?id=" + dr["ID"].ToString() + "&" + "name=" + Server.UrlEncode(dr["Name"].ToString()));
                        childElement.SetAttribute("target", "RList");
                        childElement.SetAttribute("img_src", "../images/folder.gif");
                        childElement.SetAttribute("title", dr["Name"].ToString());
                        childElement.SetAttribute("Xml", createXmlUrl + "?id=" + dr["ID"].ToString());
                        rootElement.AppendChild(childElement);
                    }
                }
            }
            string xmlStr = xmldoc.OuterXml;

            Response.Write(xmlStr);
            Response.End();
        }

        /// <summary>
        /// 用在页面的Page_Load上进行tree的结点输出
        /// </summary>
        /// <param name="dt">上级结单ID的子节点的数据集（主要字段为ID和Name两列）</param>
        /// <param name="createXmlUrl">生成XML输出的URL</param>
        /// <param name="operateUrl">树的子节点链接的URL</param>
        protected void OutTreeXml2(DataTable dt, string createXmlUrl, string operateUrl)
        {
            DataRow[] dtChild;

            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/xml";
            Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> ");

            XmlDocument xmldoc = new XmlDocument();
            XmlElement rootElement = xmldoc.CreateElement("TreeNode");
            xmldoc.AppendChild(rootElement);

            //if (dt.Rows.Count > 0)
            foreach (DataRow drParent in dt.Rows)
            {
                //DataRow drParent = dt.Rows[0];

                //if (Request.QueryString["id"].ToString() == "0")
                if (drParent["ParentID"].ToString() == "0")
                {
                    XmlElement fistElement = xmldoc.CreateElement("TreeNode");
                    fistElement.SetAttribute("id", drParent["ID"].ToString());//当前ID
                    fistElement.SetAttribute("text", drParent["Name"].ToString());//显示的文本
                    if (drParent["IsUrl"].ToString() != "0")
                        fistElement.SetAttribute("href", operateUrl + "?id=" + drParent["ID"].ToString() + "&" + "name=" + Server.UrlEncode(drParent["Name"].ToString()));

                    fistElement.SetAttribute("target", "RList");
                    fistElement.SetAttribute("img_src", "../images/folder.gif");
                    fistElement.SetAttribute("title", drParent["Name"].ToString());
                    fistElement.SetAttribute("Xml", createXmlUrl + "?id=" + drParent["ID"].ToString());
                    rootElement.AppendChild(fistElement);

                    dtChild = dt.Select(string.Format("ParentID = '{0}'", drParent["ID"].ToString()), "ID");

                    //foreach (DataRow dr in dt.Rows)
                    for (int i = 0; i < dtChild.Length; i++)
                    {
                        XmlElement childElement = xmldoc.CreateElement("TreeNode");
                        childElement.SetAttribute("id", dtChild[i]["ID"].ToString());//当前ID
                        childElement.SetAttribute("text", dtChild[i]["Name"].ToString());//显示的文本
                        if (dtChild[i]["IsUrl"].ToString() != "0")
                            childElement.SetAttribute("href", operateUrl + "?id=" + dtChild[i]["ID"].ToString() + "&" + "name=" + Server.UrlEncode(dtChild[i]["Name"].ToString()));
                        childElement.SetAttribute("target", "RList");
                        childElement.SetAttribute("img_src", "../images/folder.gif");
                        childElement.SetAttribute("title", dtChild[i]["Name"].ToString());
                        //childElement.SetAttribute("Xml", createXmlUrl + "?id=" + dtChild[i]["ID"].ToString());
                        fistElement.AppendChild(childElement);

                        //dt.Rows.Remove(dtChild[i]);
                    }

                }
                //dt.Rows.Remove(drParent);

                //else
                //{
                //    foreach (DataRow dr in dt.Rows)
                //    {
                //        XmlElement childElement = xmldoc.CreateElement("TreeNode");
                //        childElement.SetAttribute("id", dr["ID"].ToString());//当前ID
                //        childElement.SetAttribute("text", dr["Name"].ToString());//显示的文本
                //        childElement.SetAttribute("href", operateUrl + "?id=" + dr["ID"].ToString() + "&" + "name=" + Server.UrlEncode(dr["Name"].ToString()));
                //        childElement.SetAttribute("target", "RList");
                //        childElement.SetAttribute("img_src", "../images/folder.gif");
                //        childElement.SetAttribute("title", dr["Name"].ToString());
                //        childElement.SetAttribute("Xml", createXmlUrl + "?id=" + dr["ID"].ToString());
                //        rootElement.AppendChild(childElement);
                //    }
                //}
            }
            string xmlStr = xmldoc.OuterXml;

            Response.Write(xmlStr);
            Response.End();
        }


        protected void OutTreeXmlAll(DataTable dt, string createXmlUrl, string operateUrl)
        {
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/xml";
            Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> ");

            XmlDocument xmldoc = new XmlDocument();
            XmlElement rootElement = xmldoc.CreateElement("TreeNode");
            xmldoc.AppendChild(rootElement);

            foreach (DataRow dr in dt.Rows)
            {
                XmlElement fistElement = xmldoc.CreateElement("TreeNode");
                fistElement.SetAttribute("id", dr["ID"].ToString());
                fistElement.SetAttribute("text", dr["NAME"].ToString());

                int num = dt.Select("ParentID=" + dr["ID"].ToString()).Length;
                if (num > 0)
                {
                    fistElement.SetAttribute("Xml", createXmlUrl + "?id=" + dr["ID"].ToString());
                }
                else
                {
                    fistElement.SetAttribute("href", operateUrl + "?id=" + dr["ID"].ToString());
                }
                fistElement.SetAttribute("target", "RList");
                fistElement.SetAttribute("img_src", "../images/folder.gif");
                fistElement.SetAttribute("title", dr["NAME"].ToString());
                rootElement.AppendChild(fistElement);
            }

            string ss = xmldoc.OuterXml;

            Response.Write(ss);
            Response.End();
        }

        protected void OutTreeXmlAll(DataTable dt)
        {
            string createXmlUrl = Request.Url.ToString();
            string operateUrl = Request.Url.ToString();
            OutTreeXmlAll(dt, createXmlUrl, operateUrl);
        }

        /// <summary>
        /// 用在页面的Page_Load上进行tree的结点输出,url为javascript脚本事件
        /// </summary>
        /// <param name="dt">上级结单ID的子节点的数据集（主要字段为ID和Name两列）</param>
        /// <param name="createXmlUrl">生成XML输出的URL</param>
        protected void OutTreeXml(DataTable dt, string createXmlUrl)
        {
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/xml";
            Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");

            XmlDocument xmldoc = new XmlDocument();
            XmlElement rootElement = xmldoc.CreateElement("TreeNode");
            xmldoc.AppendChild(rootElement);

            if (dt.Rows.Count > 0)
            {
                DataRow drParent = dt.Rows[0];

                //if (Request.QueryString["id"].ToString() == "0")
                if (drParent["ParentID"].ToString() == "0")
                {
                    XmlElement fistElement = xmldoc.CreateElement("TreeNode");
                    fistElement.SetAttribute("id", drParent["ID"].ToString());//当前ID
                    fistElement.SetAttribute("text", drParent["Name"].ToString());//显示的文本
                    fistElement.SetAttribute("href", string.Format("javascript: ('tree_link_{0}');", drParent["ID"].ToString()));
                    fistElement.SetAttribute("img_src", "../images/folder.gif");
                    fistElement.SetAttribute("title", drParent["Name"].ToString());
                    fistElement.SetAttribute("Xml", createXmlUrl + "?id=" + drParent["ID"].ToString());
                    rootElement.AppendChild(fistElement);

                    dt.Rows.Remove(drParent);

                    foreach (DataRow dr in dt.Rows)
                    {
                        XmlElement childElement = xmldoc.CreateElement("TreeNode");
                        childElement.SetAttribute("id", dr["ID"].ToString());//当前ID
                        childElement.SetAttribute("text", dr["Name"].ToString());//显示的文本
                        childElement.SetAttribute("href", string.Format("javascript:TreeClick('tree_link_{0}');", dr["ID"].ToString()));
                        childElement.SetAttribute("img_src", "../images/folder.gif");
                        childElement.SetAttribute("title", dr["Name"].ToString());
                        childElement.SetAttribute("Xml", createXmlUrl + "?id=" + dr["ID"].ToString());
                        fistElement.AppendChild(childElement);
                    }
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        XmlElement childElement = xmldoc.CreateElement("TreeNode");
                        childElement.SetAttribute("id", dr["ID"].ToString());//当前ID
                        childElement.SetAttribute("text", dr["Name"].ToString());//显示的文本
                        childElement.SetAttribute("img_src", "../images/folder.gif");
                        childElement.SetAttribute("title", dr["Name"].ToString());

                        int num = dt.Select("ParentID=" + dr["ID"].ToString()).Length;
                        if (num > 0)
                        {
                            childElement.SetAttribute("Xml", createXmlUrl + "?id=" + dr["ID"].ToString());
                        }
                        else
                        {
                            childElement.SetAttribute("href", string.Format("javascript:TreeClick('tree_link_{0}');", dr["ID"].ToString()));
                        }
                        rootElement.AppendChild(childElement);
                    }
                }
            }
            string xmlStr = xmldoc.OuterXml;

            Response.Write(xmlStr);
            Response.End();
        }


        /// <summary>
        /// 循环输出全部树结点
        /// </summary>
        /// <param name="xmldoc">原始Xml文档</param>
        /// <param name="rootElement">上级根节点</param>
        /// <param name="dt">全部DataTable数据</param>
        /// <param name="ParentId">父Id</param>
        protected void OutDXTreeXml(XmlDocument xmldoc, XmlElement rootElement, DataTable dt, string ParentId)
        {
            foreach (DataRow dr in dt.Select("ParentID='" + ParentId + "'"))
            {
                XmlElement fistElement = xmldoc.CreateElement("item");
                fistElement.SetAttribute("id", dr["ID"].ToString());
                fistElement.SetAttribute("text", dr["LocationName"].ToString());
                rootElement.AppendChild(fistElement);

                //连接Url的结点
                //XmlElement urlElement = xmldoc.CreateElement("userdata");
                //urlElement.SetAttribute("name", "url");
                //urlElement.InnerText = "BackMoneyTjList.aspx?org=" + dr["ID"].ToString();
                //fistElement.AppendChild(urlElement);

                OutDXTreeXml(xmldoc, fistElement, dt, dr["ID"].ToString());
            }
        }

        /// <summary>
        /// 循环输出全部树结点
        /// </summary>
        /// <param name="xmldoc">原始Xml文档</param>
        /// <param name="rootElement">上级根节点</param>
        /// <param name="dt">全部DataTable数据</param>
        /// <param name="ParentId">父Id</param>
        /// <param name="ParentIDField">ParentID字段名称</param>
        /// <param name="IDField">当前ID字段名称</param>
        /// <param name="NameField">当前Name字段名称</param>
        protected void OutDXTreeXml(XmlDocument xmldoc, XmlElement rootElement, DataTable dt, string ParentId, string ParentIDField, string IDField, string NameField)
        {
            foreach (DataRow dr in dt.Select("" + ParentIDField + "='" + ParentId + "'"))
            {
                XmlElement fistElement = xmldoc.CreateElement("item");
                fistElement.SetAttribute("id", dr[IDField].ToString());
                fistElement.SetAttribute("text", dr[NameField].ToString());
                rootElement.AppendChild(fistElement);

                OutDXTreeXml(xmldoc, fistElement, dt, dr["ID"].ToString());
            }
        }

        /// <summary>
        /// 输出全部dhtmlxtree结点
        /// </summary>
        /// <param name="dt">DataTable数据(必须存在ID,Name,ParentID三个字段)</param>
        protected void OutDXTreeXmlAll(DataTable dt)
        {
            XmlDocument xmldoc = new XmlDocument();
            XmlElement rootElement = xmldoc.CreateElement("tree");
            rootElement.SetAttribute("id", "0");
            xmldoc.AppendChild(rootElement);

            OutDXTreeXml(xmldoc, rootElement, dt, "0");
            string ss = xmldoc.OuterXml;

            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/xml";
            Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
            Response.Write(ss);
            Response.End();
        }

        #region get post 数据获取方法

        public void AlertAndGo(string msg, string url)
        {
            throw new NotImplementedException();
        }

        public new NameValueCollection Form() { return HttpContext.Current.Request.Form; }
        public new string Form(int index) { return this.Form()[index]; }
        public new string Form(string key) { return this.Form()[key]; }
        /// <summary>
        /// 获取指定位置的HttpContext.Current.Request.Form 的值并转换为对应数据类型
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public decimal FormToDecimal(int index) { return ConvertUtil.ToDecimal(this.Form()[index]); }
        /// <summary>
        /// 获取指定key的HttpContext.Current.Request.Form 的值并转换为对应数据类型
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public decimal FormToDecimal(string key) { return ConvertUtil.ToDecimal(this.Form()[key]); }
        public int FormToInt(int index) { return ConvertUtil.ToInt(this.Form()[index]); }
        public int FormToInt(string key) { return ConvertUtil.ToInt(this.Form()[key]); }
        public DateTime FormToDateTime(int index) { return ConvertUtil.ToDateTime(this.Form()[index]); }
        public DateTime FormToDateTime(string key) { return ConvertUtil.ToDateTime(this.Form()[key]); }
        public bool FormToBool(int index) { return ConvertUtil.ToBool(this.Form()[index]); }
        public bool FormToBool(string key) { return ConvertUtil.ToBool(this.Form()[key]); }
        public NameValueCollection Query() { return HttpContext.Current.Request.QueryString; }
        public string Query(int index) { return this.Query()[index]; }
        public string Query(string key) { return this.Query()[key]; }
        public decimal QueryToDecimal(int index) { return ConvertUtil.ToDecimal(this.Query()[index]); }
        public decimal QueryToDecimal(string key) { return ConvertUtil.ToDecimal(this.Query()[key]); }
        public int QueryToInt(int index) { return ConvertUtil.ToInt(this.Query()[index]); }
        public int QueryToInt(string key) { return ConvertUtil.ToInt(this.Query()[key]); }
        public bool QueryToBool(int index) { return ConvertUtil.ToBool(this.Query()[index]); }
        public bool QueryToBool(string key) { return ConvertUtil.ToBool(this.Query()[key]); }
        public DateTime QueryToDateTime(int index) { return ConvertUtil.ToDateTime(this.Query()[index]); }
        public DateTime QueryToDateTime(string key) { return ConvertUtil.ToDateTime(this.Query()[key]); }
        #endregion
    }
}
